#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using Agresso.Interface.Layer.Service;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class SoftmarBunkerInventoryManagerMappingForm : Form, IFindProfitCentreParentForm
    {
        BunkerInventoryManagerMapping m_BunkerInventoryManagerMapping;
        BunkerInventoryManagerMappingService m_BunkerInventoryManagerMappingService;
        UserControlSoftmarBunkerInventoryManagerMapping m_parent;
        bool m_LEbuttonCLick = false;

        public SoftmarBunkerInventoryManagerMappingForm(BunkerInventoryManagerMapping agent, UserControlSoftmarBunkerInventoryManagerMapping parent)
        {
            InitializeComponent();
            m_parent = parent;
            m_BunkerInventoryManagerMapping = agent;
            loadData();
        }

        private void loadData()
        {
            Text = "Update Bunker Inventory Manager Mapping";
            labelTitle.Text = Text;
            m_BunkerInventoryManagerMappingService = new BunkerInventoryManagerMappingService();

            textBoxProfitCentreSoftmar.Text = m_BunkerInventoryManagerMapping.profit_centre_fullname;
            textBoxLEName.Text = m_BunkerInventoryManagerMapping.description;
            textBoxLEClient.Text = m_BunkerInventoryManagerMapping.client;
            textBoxLERelValue.Text = m_BunkerInventoryManagerMapping.rel_value;
            textBoxLEDimValue.Text = m_BunkerInventoryManagerMapping.dim_value;
            textBoxBunkerName.Text = m_BunkerInventoryManagerMapping.description_map;
            textBoxBunkerClient.Text = m_BunkerInventoryManagerMapping.client_map;
            textBoxBunkerRelValue.Text = m_BunkerInventoryManagerMapping.rel_value_map;
            textBoxBunkerDimValue.Text = m_BunkerInventoryManagerMapping.dim_value_map;
        }
        public SoftmarBunkerInventoryManagerMappingForm(string agent)
        {
            InitializeComponent();
            m_BunkerInventoryManagerMapping = m_BunkerInventoryManagerMappingService.SearchInsert(agent, "", "", "", "");
            loadData();
        }

        private void button1OK_Click(object sender, EventArgs e)
        {
            updateBunkerInventoryMap();
            this.Close();
        }

        private void updateBunkerInventoryMap()
        {
            m_BunkerInventoryManagerMapping.description = textBoxLEName.Text;
            m_BunkerInventoryManagerMapping.client = textBoxLEClient.Text;
            m_BunkerInventoryManagerMapping.rel_value = textBoxLERelValue.Text;
            m_BunkerInventoryManagerMapping.dim_value = textBoxLEDimValue.Text;

            m_BunkerInventoryManagerMapping.description_map = textBoxBunkerName.Text;
            m_BunkerInventoryManagerMapping.client_map = textBoxBunkerClient.Text;
            m_BunkerInventoryManagerMapping.rel_value_map = textBoxBunkerRelValue.Text;
            m_BunkerInventoryManagerMapping.dim_value_map = textBoxBunkerDimValue.Text;

            m_BunkerInventoryManagerMappingService.Update(m_BunkerInventoryManagerMapping);
            if (m_parent != null)
                m_parent.UpdateSelectedItem(m_BunkerInventoryManagerMapping);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            updateBunkerInventoryMap();
            buttonApply.Enabled = false;
        }

        private void DADeskVesselForm_Load(object sender, EventArgs e)
        {
            textBoxBunkerClient.Focus();
        }

        private void activate_apply(object sender, KeyPressEventArgs e)
        {
            buttonApply.Enabled = true;
        }

        private void buttonSearchLE_Click(object sender, EventArgs e)
        {
            m_LEbuttonCLick = true;
            activate_apply(null, null);
            FindProfitCentreForm fform = new FindProfitCentreForm(this);
            fform.ShowDialog();
        }

        public string GetProftCentreName()
        {
            return m_BunkerInventoryManagerMapping.profit_centre_fullname;
        }

        public void UpdateAgressoProfitCentre(agldimvalue acu)
        {
            if (m_LEbuttonCLick)
            {
                textBoxLEName.Text = acu.description;
                textBoxLEClient.Text = acu.client;
                textBoxLERelValue.Text = acu.rel_value;
                textBoxLEDimValue.Text = acu.dim_value;
            }
            else
            {
                textBoxBunkerName.Text = acu.description;
                textBoxBunkerClient.Text = acu.client;
                textBoxBunkerRelValue.Text = acu.rel_value;
                textBoxBunkerDimValue.Text = acu.dim_value;
            }
        }

        private void buttonSearchBunker_Click(object sender, EventArgs e)
        {
            m_LEbuttonCLick = false;
            activate_apply(null, null);
            FindProfitCentreForm fform = new FindProfitCentreForm(this);
            fform.ShowDialog();
        }

        private void labelTitle_Click(object sender, EventArgs e)
        {

        }
    }
}